<?php
declare(strict_types=1);

namespace Service\CommodityService;

use Service\BaseService;
use Service\Code\Normal;
use App\Model\BbcModel\Goods;
use App\Model\BbcModel\GoodsBrand;
use App\Model\BbcModel\MnStoreGoods;
use App\Model\BbcModel\Mnuser;
use Service\EsService\EsPublishMsgService;

/**
 * 渠道商品ES相关服务
 * @author huj
 */
class ChannelCommodityEsService extends BaseService
{
    /**
     * 通过分类更新ES索引
     * @param integer $class_id
     * @param integer $cid
     */
    public function updateIndexByClassId($class_id, $cid) {
        if (!isset($class_id) || empty($class_id) || (preg_match("/^[1-9]\d*$/", (string)$class_id) != 1)) {
            return Normal::returnCode(Normal::FAIL, 'invalid argument class_id');
        }
        if (!isset($cid) || empty($cid) || (preg_match("/^[1-9]\d*$/", (string)$cid) != 1)) {
            return Normal::returnCode(Normal::FAIL, 'invalid argument cid');
        }
        $cid       = (int)$cid;
        $class_id  = (int)$class_id;
        $brandList = GoodsBrand::pluck('name', 'id')->toArray();
        $fields    = ['id', 'name', 'brand_id', 'status', 'is_trade'];
        $goodsList = Goods::where('class_id', $class_id)->where('cid', $cid)->where('df', 0)->select($fields)->get()->toArray();
        if ($goodsList) {
            $ids           = array_column($goodsList, 'id');
            $goodsIndex    = array_column($goodsList, null, 'id');
            $channelInsert = [];
            //大贸批次商品不能进行代发售卖,更新渠道搜索索引
            foreach ($goodsList as $v) {
                if ($v['is_trade'] == 0) {
                    $updateIndexData['id']                   = $v['id'];
                    $updateIndexData['goodsId']              = $v['id'];
                    $updateIndexData['name']                 = $v['name'];
                    $updateIndexData['classifyID']           = $class_id;
                    $updateIndexData['channelID']            = $cid;
                    $updateIndexData['isTrade']              = 0;
                    $updateIndexData['brandName']            = $brandList[$v['brand_id']];
                    $updateIndexData['isChannelGoodsActive'] = $v['status'] > 0;
                    $channelInsert[]                         = $updateIndexData;
                }
            }
            if (!empty($channelInsert)) {
                // Rbq::instance()->pushNew($channelInsert,'channel','insert');
                EsPublishMsgService::instance()->channelESMessageProducer(['actionType' => 'CommodityChange', 'datas' => $channelInsert]);
            }
            //更新店铺搜索索引
            // $storeGoodsList=MnStoreGoods::instance()->lists([['goods_id','in',$ids],'_fields_'=>'id,mn_sid,status,goods_id']);
            $storeGoodsList = MnStoreGoods::whereIn('goods_id', $ids)->select(['id', 'mn_sid', 'status', 'goods_id'])->get()->toArray();
            $insertData     = [];
            foreach ($storeGoodsList as $keys => $values) {
                $insertItem['id']                   = $values['id'];
                $insertItem['goodsId']              = $values['goods_id'];
                $insertItem['name']                 = $goodsIndex[$values['goods_id']]['name'];
                $insertItem['classifyID']           = $class_id;
                $insertItem['storeID']              = $values['mn_sid'];
                $insertItem['channelID']            = $cid;
                $insertItem['isTrade']              = $goodsIndex[$values['goods_id']]['is_trade'];
                $insertItem['brandName']            = $brandList[$goodsIndex[$values['goods_id']]['brand_id']];
                $insertItem['isChannelGoodsActive'] = $goodsIndex[$values['goods_id']]['status'] > 0;
                $insertItem['isStoreGoodsActive']   = $values['status'] > 0;
                $insertData[]                       = $insertItem;
            }
            if (!empty($insertData)) {
                // Rbq::instance()->pushNew($insertData,'store','insert');
                EsPublishMsgService::instance()->storeESMessageProducer(['actionType' => 'CommodityChange', 'datas' => $insertData]);
            }
        }
        return Normal::returnCode(Normal::SUC, "发布成功");
    }

    /**
     * 商品上下架后更新ES索引
     * @param array $param
     * @param integer $is_sp 0代发商品 1前置仓
     */
    public function updateIndexByOnlineStatus($param, $is_sp = 0) {
        if (!isset($param['cid']) || empty($param['cid']) || (preg_match("/^[1-9]\d*$/", (string)$param['cid']) != 1)) {
            return Normal::returnCode(Normal::FAIL, 'invalid argument cid');
        }
        if (!isset($param['status']) || !in_array($param['status'], ['1', '0'])) {
            return Normal::returnCode(Normal::FAIL, 'invalid argument status');
        }
        if (!isset($param['goods_ids']) || empty($param['goods_ids']) || !is_array($param['goods_ids'])) {
            return Normal::returnCode(Normal::FAIL, 'invalid argument goods_ids');
        }
        $cid     = (int)$param['cid'];
        $isTrade = $param['is_trade'] ?? 0;
        $fields  = ['id', 'is_trade', 'class_id', 'name', 'brand_id', 'status', 'price_recommend', 'price_recommend_vip', 'supplier_id', 'is_fast_delivery'];
        $model   = Goods::whereIn('id', $param['goods_ids'])->where('cid', $cid)->where('is_trade', $isTrade)->where('df', 0);
        if($is_sp == 1){
            $model = $model->where('is_fast_delivery', 1);
        }else{
            $model = $model->where('is_fast_delivery', '<>', 1);
        }
        if ($param['status'] == 1 && $isTrade == 0) {
            $model = $model->whereRaw(" num_storage>0 and price_cost <= price_store and price_recommend>=price_store and price_recommend_vip>=price_store");
        }
        $goods      = $model->select($fields)->get()->toArray();
        $ids        = array_column($goods, 'id');
        $down_ids   = [];
        $goodsIndex = array_column($goods, null, 'id');
        $brandList  = GoodsBrand::pluck('name', 'id')->toArray();;
        $channelInsert   = [];
        $mnuser          = Mnuser::where('pid', $cid)->where('auto_up', 1)->select(['id', 'mid', 'type', 'supplier_id', 'goods_source', 'sid'])->get()->toArray();
        $mnuser_ids      = array_column($mnuser, 'id');
        $allMnStoreGoods = MnStoreGoods::whereIn('goods_id', $ids)->whereIn('mn_sid', $mnuser_ids)->select(['id', 'goods_id', 'mn_sid'])->get();
        $insert          = [];
        //大贸批次商品不能进行代发售卖
        foreach ($goods as $v) {
            $down_ids[] = $v['id'];
            if ($v['is_trade'] == 1) {
                continue;
            }
            $updateIndexData['id']                   = $v['id'];
            $updateIndexData['goodsId']              = $v['id'];
            $updateIndexData['name']                 = $v['name'];
            $updateIndexData['classifyID']           = $v['class_id'];
            $updateIndexData['channelID']            = $cid;
            $updateIndexData['isTrade']              = 0;
            $updateIndexData['brandName']            = $brandList[$v['brand_id']];
            $updateIndexData['isChannelGoodsActive'] = $param['status'] > 0;
            $channelInsert[]                         = $updateIndexData;
            if ($param['status'] == 1) {
                foreach ($mnuser as $store) {
                    if ($v['is_fast_delivery'] == 1 && $store['supplier_id'] == $v['supplier_id'] && in_array($store['goods_source'], [2, 3, 6, 7]) && $store['type'] == 3) {
                        // $has=MnStoreGoods::instance()->info(['goods_id'=>$v['id'],'mn_sid'=>$store['id'],'_fields_'=>'id']);
                        $has = $allMnStoreGoods->where('goods_id', $v['id'])->where('mn_sid', $store['id'])->first();
                    } else if ($v['is_fast_delivery'] == 2 && in_array($store['type'], [1, 2])) {
                        $has = $allMnStoreGoods->where('goods_id', $v['id'])->where('mn_sid', $store['id'])->first();
                    } else if ($v['is_fast_delivery'] == 2 && $store['type'] == 3 && in_array($store['goods_source'], [4, 5, 6, 7])) {
                        $has = $allMnStoreGoods->where('goods_id', $v['id'])->where('mn_sid', $store['id'])->first();
                    } else if ($v['is_fast_delivery'] == 0 && in_array($store['type'], [1, 2])) {
                        $has = $allMnStoreGoods->where('goods_id', $v['id'])->where('mn_sid', $store['id'])->first();
                    } else if ($v['is_fast_delivery'] == 0 && $store['type'] == 3 && in_array($store['goods_source'], [1, 5, 3, 7])) {
                        $has = $allMnStoreGoods->where('goods_id', $v['id'])->where('mn_sid', $store['id'])->first();
                    } else {
                        continue;
                    }
                    if (empty($has)) {
                        $item              = [];
                        $item['sid']       = $store['sid'];
                        $item['mn_sid']    = $store['id'];
                        $item['mid']       = $store['mid'];
                        $item['goods_id']  = $v['id'];
                        $item['status']    = 1;
                        $item['type']      = 2;
                        $item['cd']        = time();
                        $item['md']        = time();
                        $item['price']     = $v['price_recommend'];
                        $item['price_vip'] = $v['price_recommend_vip'];
                        $insert[]          = $item;
                    }
                }
            }
        }
        if (!empty($insert)) {
            MnStoreGoods::insert($insert);
        }
        if (!empty($channelInsert)) {
            // Rbq::instance()->pushNew($channelInsert,'channel','insert');
            EsPublishMsgService::instance()->channelESMessageProducer(['actionType' => 'CommodityChange', 'datas' => $channelInsert]);
        }
        if ($param['status'] == 0) {
            //渠道下架商品，Q店则删除这些商品，更新索引
            MnStoreGoods::whereIn('goods_id', $down_ids)->update(['df' => 1]);
            $storeGoodsList = MnStoreGoods::whereIn('goods_id', $down_ids)->select(['id'])->get()->toArray();
            if (!empty($storeGoodsList)) {
                // Rbq::instance()->pushNew(array_column($storeGoodsList,'id'),'store','delete');
                EsPublishMsgService::instance()->storeESMessageProducer(['actionType' => 'CommodityBatchDel', 'datas' => $storeGoodsList]);
            }
        } else {
            $allStore    = Mnuser::where('pid', $cid)->where('check_status', 1)->where('status', 1)->select(['id', 'supplier_id', 'type', 'goods_source', 'is_pay', 'new_store'])->get();
            $onlineStore = $allStore->where('is_pay', 1)->whereIn('type', [1, 2])->pluck('id')->toArray();
            if ($onlineStore) {
                MnStoreGoods::whereIn('goods_id', $down_ids)->whereIn('mn_sid', $onlineStore)->update(['df' => 0]);
                $storeGoodsList = MnStoreGoods::whereIn('goods_id', $down_ids)->whereIn('mn_sid', $onlineStore)->select(['id', 'mn_sid', 'status', 'goods_id'])->get()->toArray();
                $insertData     = [];
                foreach ($storeGoodsList as $keys => $values) {
                    $insertItem['id']                   = $values['id'];
                    $insertItem['goodsId']              = $values['goods_id'];
                    $insertItem['name']                 = $goodsIndex[$values['goods_id']]['name'];
                    $insertItem['classifyID']           = $goodsIndex[$values['goods_id']]['class_id'];
                    $insertItem['storeID']              = $values['mn_sid'];
                    $insertItem['channelID']            = $cid;
                    $insertItem['isTrade']              = $goodsIndex[$values['goods_id']]['is_trade'];
                    $insertItem['brandName']            = $brandList[$goodsIndex[$values['goods_id']]['brand_id']];
                    $insertItem['isStoreGoodsActive']   = $values['status'] > 0;
                    $insertItem['isChannelGoodsActive'] = true;
                    $insertData[]                       = $insertItem;
                }
                if (!empty($insertData)) {
                    // Rbq::instance()->pushNew($insertData,'store','insert');
                    EsPublishMsgService::instance()->storeESMessageProducer(['actionType' => 'CommodityChange', 'datas' => $insertData]);
                }
            }
            $offlineBondedStore = $allStore->where('new_store', 1)->where('type', 3)->toArray();
            if ($offlineBondedStore) {
                $insertData          = [];
                $BondStoreGoodsList  = [];
                $downMnIds           = array_column($offlineBondedStore, 'id');
                $allDownMnStoreGoods = MnStoreGoods::whereIn('goods_id', $ids)->whereIn('mn_sid', $downMnIds)->get();
                foreach ($ids as $key => $goodsid) {
                    foreach ($offlineBondedStore as $k => $v) {
                        if ($goodsIndex[$goodsid]['is_fast_delivery'] == 1 && $v['type'] == 3 && $v['supplier_id'] == $goodsIndex[$goodsid]['supplier_id'] && in_array($v['goods_source'], [2, 3, 6, 7])) {
                            $BondStoremnstoregoods = $allDownMnStoreGoods->where('goods_id', $goodsid)->where('mn_sid', $v['id'])->first();
                        } else if ($goodsIndex[$goodsid]['is_fast_delivery'] == 2 && in_array($v['type'], [1, 2])) {
                            $BondStoremnstoregoods = $allDownMnStoreGoods->where('goods_id', $goodsid)->where('mn_sid', $v['id'])->first();
                        } else if ($goodsIndex[$goodsid]['is_fast_delivery'] == 2 && $v['type'] == 3 && in_array($v['goods_source'], [4, 5, 6, 7])) {
                            $BondStoremnstoregoods = $allDownMnStoreGoods->where('goods_id', $goodsid)->where('mn_sid', $v['id'])->first();
                        } else if ($goodsIndex[$goodsid]['is_fast_delivery'] == 0 && in_array($v['type'], [1, 2])) {
                            $BondStoremnstoregoods = $allDownMnStoreGoods->where('goods_id', $goodsid)->where('mn_sid', $v['id'])->first();
                        } else if ($goodsIndex[$goodsid]['is_fast_delivery'] == 0 && $v['type'] == 3 && in_array($v['goods_source'], [1, 5, 3, 7])) {
                            $BondStoremnstoregoods = $allDownMnStoreGoods->where('goods_id', $goodsid)->where('mn_sid', $v['id'])->first();
                        } else {
                            continue;
                        }
                        if ($BondStoremnstoregoods) {
                            $BondStoreGoodsList[] = $BondStoremnstoregoods->toArray();
                        }
                    }
                }
                if (!empty($BondStoreGoodsList)) {
                    // MnStoreGoods::instance()->edit(['id'=>array_column($BondStoreGoodsList,'id')],['df'=>0]);
                    MnStoreGoods::whereIn('id', array_column($BondStoreGoodsList, 'id'))->update(['df' => 0]);
                    foreach ($BondStoreGoodsList as $item) {
                        $insertItem['id']                   = $item['id'];
                        $insertItem['goodsId']              = $item['goods_id'];
                        $insertItem['name']                 = $goodsIndex[$item['goods_id']]['name'];
                        $insertItem['classifyID']           = $goodsIndex[$item['goods_id']]['class_id'];
                        $insertItem['isTrade']              = $goodsIndex[$item['goods_id']]['is_trade'];
                        $insertItem['storeID']              = $item['mn_sid'];
                        $insertItem['channelID']            = $cid;
                        $insertItem['brandName']            = $brandList[$goodsIndex[$item['goods_id']]['brand_id']];
                        $insertItem['isStoreGoodsActive']   = $item['status'] > 0;
                        $insertItem['isChannelGoodsActive'] = true;
                        $insertData[]                       = $insertItem;
                    }
                }
                if (!empty($insertData)) {
                    // Rbq::instance()->pushNew($insertData,'store','insert');
                    EsPublishMsgService::instance()->storeESMessageProducer(['actionType' => 'CommodityChange', 'datas' => $insertData]);
                }
            }
            return Normal::returnCode(Normal::SUC, "发布成功");
        }
    }

    /**
     * 更新单个商品ES索引
     * @param array $param
     */
    public function updateIndexBySingleGoods($goods_id, $cid) {
        if (!isset($goods_id) || empty($goods_id) || (preg_match("/^[1-9]\d*$/", (string)$goods_id) != 1)) {
            return Normal::returnCode(Normal::FAIL, 'invalid argument goods_id');
        }
        if (!isset($cid) || empty($cid) || (preg_match("/^[1-9]\d*$/", (string)$cid) != 1)) {
            return Normal::returnCode(Normal::FAIL, 'invalid argument cid');
        }
        $goodsInfo = Goods::where('id', $goods_id)->where('cid', $cid)->first();
        if (empty($goodsInfo)) {
            return Normal::returnCode(Normal::FAIL, "指定商品信息不存在");
        }
        $goodsInfo = $goodsInfo->toArray();
        $brand     = GoodsBrand::where('id', $goodsInfo['brand_id'])->first();
        if (empty($brand)) {
            return Normal::returnCode(Normal::FAIL, "指定商品品牌信息不存在");
        }
        $brand = $brand->toArray();
        if ($goodsInfo['is_trade'] == 0) {
            //代发商品更新渠道商品索引
            $updateIndexData['id']                   = $goodsInfo['id'];
            $updateIndexData['goodsId']              = $goodsInfo['id'];
            $updateIndexData['name']                 = $goodsInfo['name'];
            $updateIndexData['classifyID']           = $goodsInfo['class_id'];
            $updateIndexData['channelID']            = $cid;
            $updateIndexData['brandName']            = $brand['name'];
            $updateIndexData['isTrade']              = $goodsInfo['is_trade'];
            $updateIndexData['isChannelGoodsActive'] = $goodsInfo['status'] > 0;
            $channelInsert[]                         = $updateIndexData;
            // Rbq::instance()->pushNew($channelInsert,'channel','insert');
            EsPublishMsgService::instance()->channelESMessageProducer(['actionType' => 'CommodityChange', 'datas' => $channelInsert]);

        }
        if ($goodsInfo['status'] == 0) {
            if ($goodsInfo['is_trade'] == 0) {
                $storeGoodsList = MnStoreGoods::where('goods_id', $goodsInfo['id'])->select(['id'])->get()->toArray();
                if (!empty($storeGoodsList)) {
                    // Rbq::instance()->pushNew([$goodsInfo['id']],'channel','delete');
                    EsPublishMsgService::instance()->channelESMessageProducer(['actionType' => 'CommodityBatchDel', 'datas' => [$goodsInfo['id']]]);
                }
                MnStoreGoods::whereIn('id', array_column($storeGoodsList, 'id'))->update(['df' => 1]);
            } else {
                $storeGoodsList = MnStoreGoods::where('goods_id', $goodsInfo['id'])->where('num', 0)->where('pre_storage', 0)->select(['id', 'goods_id', 'mn_sid'])->get()->toArray();
                $insertData     = [];
                foreach ($storeGoodsList as $keys => $values) {
                    $insertItem['id']                   = $values['id'];
                    $insertItem['goodsId']              = $values['goods_id'];
                    $insertItem['name']                 = $goodsInfo['name'];
                    $insertItem['classifyID']           = $goodsInfo['class_id'];
                    $insertItem['storeID']              = $values['mn_sid'];
                    $insertItem['brandName']            = $brand['name'];
                    $insertItem['isTrade']              = $goodsInfo['is_trade'];
                    $insertItem['channelID']            = $cid;
                    $insertItem['isChannelGoodsActive'] = false;
                    $insertItem['isStoreGoodsActive']   = false;
                    $insertData[]                       = $insertItem;
                }
                if (!empty($insertData)) {
                    // Rbq::instance()->pushNew($insertData,'store','insert');
                    EsPublishMsgService::instance()->storeESMessageProducer(['actionType' => 'CommodityChange', 'datas' => $insertData]);
                }
                MnStoreGoods::where('goods_id', $goodsInfo['id'])->where('num', 0)->update(['df' => 1, 'pre_sell' => 0]);
            }
        } else {
            if ($goodsInfo['is_trade'] == 0) {
                MnStoreGoods::where('goods_id', $goodsInfo['id'])->update(['df' => 0]);
                $storeGoodsList = MnStoreGoods::where('goods_id', $goodsInfo['id'])->select(['id', 'goods_id', 'mn_sid', 'status'])->get()->toArray();
                $insertData     = [];
                foreach ($storeGoodsList as $keys => $values) {
                    $insertItem['id']                   = $values['id'];
                    $insertItem['goodsId']              = $values['goods_id'];
                    $insertItem['name']                 = $goodsInfo['name'];
                    $insertItem['classifyID']           = $goodsInfo['class_id'];
                    $insertItem['storeID']              = $values['mn_sid'];
                    $insertItem['brandName']            = $brand['name'];
                    $insertItem['isTrade']              = $goodsInfo['is_trade'];
                    $insertItem['channelID']            = $cid;
                    $insertItem['isChannelGoodsActive'] = true;
                    $insertItem['isStoreGoodsActive']   = $values['status'] > 0;
                    $insertData[]                       = $insertItem;
                }
                if (!empty($insertData)) {
                    // Rbq::instance()->pushNew($insertData,'store','insert');
                    EsPublishMsgService::instance()->storeESMessageProducer(['actionType' => 'CommodityChange', 'datas' => $insertData]);
                }
            } else {
                MnStoreGoods::where('goods_id', $goodsInfo['id'])->update(['df' => 0]);
                $storeGoodsList = MnStoreGoods::where('goods_id', $goodsInfo['id'])->where('num', '>', 0)->select(['id', 'goods_id', 'mn_sid', 'status'])->get()->toArray();
                $insertData     = [];
                foreach ($storeGoodsList as $keys => $values) {
                    $insertItem['id']                   = $values['id'];
                    $insertItem['goodsId']              = $values['goods_id'];
                    $insertItem['name']                 = $goodsInfo['name'];
                    $insertItem['classifyID']           = $goodsInfo['class_id'];
                    $insertItem['storeID']              = $values['mn_sid'];
                    $insertItem['brandName']            = $brand['name'];
                    $insertItem['isTrade']              = $goodsInfo['is_trade'];
                    $insertItem['channelID']            = $cid;
                    $insertItem['isChannelGoodsActive'] = true;
                    $insertItem['isStoreGoodsActive']   = $values['status'] > 0;
                    $insertData[]                       = $insertItem;
                }
                if (!empty($insertData)) {
                    // Rbq::instance()->pushNew($insertData,'store','insert');
                    EsPublishMsgService::instance()->storeESMessageProducer(['actionType' => 'CommodityChange', 'datas' => $insertData]);
                }
            }
        }
        return Normal::returnCode(Normal::SUC, "发布成功");
    }

    /**
     * 更新多个商品ES索引
     * @param array $param
     */
    public function updateIndexByBatchGoods($goods_ids, $cid) {
        $fields        = ['id', 'name', 'brand_id', 'status', 'is_trade', 'class_id'];
        $goods         = Goods::whereIn('id', $goods_ids)->where('cid', $cid)->where('df', 0)->select($fields)->get()->toArray();
        $goodsIndex    = array_column($goods, null, 'id');
        $brandList     = GoodsBrand::pluck('name', 'id')->toArray();
        $channelInsert = [];
        //大贸批次商品不能进行代发售卖
        foreach ($goods as $v) {
            if ($v['is_trade'] == 1) {
                continue;
            }
            $updateIndexData['id']                   = $v['id'];
            $updateIndexData['goodsId']              = $v['id'];
            $updateIndexData['name']                 = $v['name'];
            $updateIndexData['classifyID']           = $v['class_id'];
            $updateIndexData['channelID']            = $cid;
            $updateIndexData['brandName']            = $brandList[$v['brand_id']];
            $updateIndexData['isTrade']              = 0;
            $updateIndexData['isChannelGoodsActive'] = $v['status'] > 0;
            $channelInsert[]                         = $updateIndexData;
        }
        if (!empty($channelInsert)) {
            // Rbq::instance()->pushNew($channelInsert,'channel','insert');
            EsPublishMsgService::instance()->channelESMessageProducer(['actionType' => 'CommodityChange', 'datas' => $channelInsert]);
        }
        $i              = 0;
        $flag           = true;
        $storeGoodsList = MnStoreGoods::whereIn('goods_id', $goods_ids)->select(['id', 'mn_sid', 'status', 'goods_id'])->get()->toArray();
        $insertData     = [];
        foreach ($storeGoodsList as $values) {
            $insertItem['id']                   = $values['id'];
            $insertItem['goodsId']              = $values['goods_id'];
            $insertItem['name']                 = $goodsIndex[$values['goods_id']]['name'];
            $insertItem['classifyID']           = $goodsIndex[$values['goods_id']]['class_id'];
            $insertItem['storeID']              = $values['mn_sid'];
            $insertItem['channelID']            = $cid;
            $insertItem['brandName']            = $brandList[$goodsIndex[$values['goods_id']]['brand_id']];
            $insertItem['isTrade']              = $goodsIndex[$values['goods_id']]['is_trade'];
            $insertItem['isChannelGoodsActive'] = $goodsIndex[$values['goods_id']]['status'] > 0;
            $insertItem['isStoreGoodsActive']   = $values['status'] > 0;
            $insertData[]                       = $insertItem;
        }
        if (!empty($insertData)) {
            // Rbq::instance()->pushNew($insertData, 'store', 'insert');
            EsPublishMsgService::instance()->storeESMessageProducer(['actionType' => 'CommodityChange', 'datas' => $insertData]);
        }
    }
}